{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Using SG-Net encoded features for RAG\n",
    "In SG-Reg, we encode multiple modality of a semantic node:\n",
    "- Local topology feature $\\mathbf{x}$.\n",
    "- Shape feature $\\mathbf{f}$.\n",
    "- Dense point feature $\\mathbf{z}$.\n",
    "\n",
    "\n",
    "<p align=\"center\">\n",
    "    <img src=\"explicit_sg.png\" width=\"800\"/>\n",
    "</p>\n",
    "\n",
    "We encode these features on ScanNet dataset. Please use the following code to load the data.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Read implicit features\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Load 20 features from /data2/ScanNetRag/val/scene0025_00c\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import torch\n",
    "\n",
    "scene_dir = '/data2/ScanNetRag/val/scene0025_00c'\n",
    "feature_dict = torch.load(scene_dir + '/features.pth')\n",
    "x = feature_dict['x'] # (N,d)\n",
    "f = feature_dict['f'] # (N,ds)\n",
    "labels = feature_dict['labels'] # (N,)\n",
    "N = x.shape[0]\n",
    "\n",
    "print('Load {} features from {}'.format(N, scene_dir))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Read tags from RAM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The scene has tags: armchair, black, bureau, cart, chair, couch, table, drawer, dresser, file cabinet, floor, nightstand, room, stool, waiting room, attach, board, bottle, wall, bulletin board, classroom, note, office supply, whiteboard, write, writing, magnet, white, carpet, closet, corner, pad, gray, hassock, living room, pillow, throw pillow, footrest, hospital room, air conditioner, blue, office, radiator, ceiling fan, door, fan, computer, doorway, electronic, equipment, floor fan, shelf, speaker, cabinet, computer desk, file, office chair, office desk, shelve, swivel chair, hide, bin, computer monitor, lamp, hang, mark, office building, computer screen, desktop, desktop computer, monitor, office cubicle, pen, \n",
      "\n"
     ]
    }
   ],
   "source": [
    "\n",
    "with open(scene_dir + '/tags.txt', 'r') as f:\n",
    "    tags = f.readlines()[0]\n",
    "    f.close()\n",
    "\n",
    "    print('The scene has tags: {}'.format(tags))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Visualize a scene (have not tested)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import open3d as o3d \n",
    "from open3d.web_visualizer import draw\n",
    "\n",
    "explicit_scene_folder = '/data2/ScanNetGraph/val/scene0064_00c'\n",
    "\n",
    "instance_map_dir = os.path.join(explicit_scene_folder, '0002.ply')\n",
    "pcd = o3d.io.read_point_cloud(instance_map_dir)\n",
    "print('Load {} points from {}'.format(len(pcd.points), instance_map_dir))\n",
    "# draw([pcd, pcd])\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "sgnet",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
